package com.imooc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.mapper.IndustryMapper;
import com.imooc.pojo.Industry;
import com.imooc.service.IndustryService;
import com.imooc.vo.TopIdAndThirdIndustryListVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 行业表 服务实现类
 * </p>
 *
 * @author liansen
 * @since 2023-03-28
 */
@Service
public class IndustryServiceImpl extends ServiceImpl<IndustryMapper, Industry> implements IndustryService {

    @Override
    public boolean getIndustryByName(String name) {
        LambdaQueryWrapper<Industry> wrapper = new LambdaQueryWrapper<Industry>().eq(Industry::getName, name);
        Industry industry = baseMapper.selectOne(wrapper);
        return industry != null ? true : false;
    }

    @Override
    public List<Industry> getTopList() {
        return getChildrenIndustryList("0");
    }

    @Override
    public List<Industry> getChildrenIndustryList(String id) {
        LambdaQueryWrapper<Industry> wrapper = new LambdaQueryWrapper<Industry>()
                .eq(Industry::getFatherId, id)
                .orderByAsc(Industry::getSort);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public Long getChildrenCounts(String id) {
        LambdaQueryWrapper<Industry> wrapper = new LambdaQueryWrapper<Industry>().eq(Industry::getFatherId, id);
        return baseMapper.selectCount(wrapper);
    }

    @Override
    public List<Industry> getThirdList(String topId) {
        return baseMapper.selectThirdList(topId);
    }

    @Override
    public String getTopIndustryIdByThirdIndustryId(String id) {
        return baseMapper.getTopIndustryIdByThirdIndustryId(id);
    }

    @Override
    public List<TopIdAndThirdIndustryListVO> getTopIdAndThirdList() {
        return baseMapper.getTopIdAndThirdList();
    }
}
